import json

import requests

if __name__ == "__main__":
    word = input("enter a word:")
    data = {
        "kw": word
    }

    post_url = "https://fanyi.baidu.com/sug"
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36',
    }
    response = requests.post(url=post_url, headers=headers, data=data)
    json_data = response.json()
    print(json_data)

    fileName = word + ".json"
    fp = open(fileName, "w", encoding="utf-8")
    json.dump(json_data, fp, ensure_ascii=False)
    print("write [" + fileName + "] OK!!")
